/**
 * 
 */
package neptune.manager.validator.rules.netif;

import neptune.manager.model.topology.IPAddress;
import neptune.manager.model.topology.NetworkInterface;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.ValidatorRule;
import neptune.manager.validator.Validator.Status;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class ControlAddressNumberRule extends ValidatorRule<NetworkInterface> {

	@Override
	public String getName() {
		return "ControlAddressNumberRule";
	}

	@Override
	protected ValidatorResult validationAlgorithm(NetworkInterface toValidate,
			ValidatorResult result) {

		int controlAddrNumber = 0;

		for (IPAddress ipAddr : toValidate.getIpAddresses()) {
			if (ipAddr.isControlAddress())
				controlAddrNumber++;
		}

		if (controlAddrNumber > 1) {
			result.setStatus(Status.ERROR);
			result.getLog().addMessage("More than 1 control address defined",
					MessageType.ERROR);
		}

		return result;
	}

}
